package treeset;

import java.util.Objects;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : person
 * @Author : 54061
 * @Date: 2022/2/9 10:45
 */
public class Person implements Comparable<Person> {
    private String name;
    private int age;
    private int Chinese;
    private int math;
    private int English;

    public Person() {
    }

    public Person(String name, int age, int chinese, int math, int english) {
        this.name = name;
        this.age = age;
        Chinese = chinese;
        this.math = math;
        English = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getChinese() {
        return Chinese;
    }

    public void setChinese(int chinese) {
        Chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return English;
    }

    public void setEnglish(int english) {
        English = english;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                Chinese == person.Chinese &&
                math == person.math &&
                English == person.English &&
                Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, Chinese, math, English);
    }

    @Override
    public String toString() {
        return "person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", Chinese=" + Chinese +
                ", math=" + math +
                ", English=" + English +
                "}"+ getSum();
    }
    public int getSum(){
        return Chinese + math + English;
    }

    @Override
    public int compareTo(Person o) {
        //成绩降序
        int result = o.getSum() - this.getSum();
        //语文降序
        result = result == 0 ? o.Chinese - this.Chinese : result;
        //数学降序
        result = result == 0 ? o.math - this.math : result;
        //年龄升序
        result = result == 0 ? this.age - o.age : result;
        //姓名首字母的升序 (字符串就可以调用字符串自己的排序方法)
        result = result == 0 ? this.name.compareToIgnoreCase(o.name) :result;
        return result;
    }
}
